
// import SaSelectBool from '@/components/Tool/sa-select-bool.vue'
// import SaSelectProduct from '@/components/Tool/sa-select-product.vue'
// import SaSelectCustType from '@/components/Tool/sa-select-custType.vue'
// import SaSelectDept from '@/components/Tool/sa-select-dept.vue'
// import SaDatePicker from '@/components/Tool/sa-datePicker.vue'

import TrustPagination from '@/views/custom/tool/trust-pagination';
import TrustQueryFilterOperation from '@/views/custom/tool/trust-query-filter-operation';
import ZDate from '@/views/custom/tool/z-date';
import request from '@/utils/request'


export const saTableMixin = {

  components: { TrustPagination, TrustQueryFilterOperation,ZDate },
  data(){
    return{
      queryParams:{
        pageNum:1,
        pageSize:20,
      },
      //固定参数
      queryRegularParams:{

      },
      searchAdvanced:false,
      tableList:[],
      total:0,
      urlStr:"",
      method:"",
      loading:false,
      multipleSelection:[],
    }
  },
  methods:{
    fIndex(index){
      return index + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize;
    },
    fMoney(row, column, cellValue, index){
      let money = parseFloat(cellValue);
      if (isNaN(money)){
        return cellValue;
      }
      let f = Math.round(money*100)/100;
      let s = f.toString()
      let  rs = s.indexOf('.');
      if (rs < 0){
        rs = s.length;
        s += '.';
      }
      while ( s.length <= rs + 2){
        s += '0';
      }
      let fmoney = `${s}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      return fmoney;
    },
    fDate(row, column, cellValue, index){
      let date = new Date(cellValue);
      return ZDate.toFormatString("yyyy-MM-dd hh:mm:ss",date);
    },
    fBool(row, column, cellValue, index){
      if (cellValue === 1){
        return "是";
      }
      return "否";
    },
    requestData(url, method, params) {
      this.loading = true;
      this.urlStr = url;
      this.method = method;
      let combinedObj = {}

      for (let key in this.queryRegularParams) {
        combinedObj[key] = this.queryRegularParams[key]
      }
      for (let key in params) {
        combinedObj[key] = params[key]
      }
      // let combinedObj = Object.assign( this.queryRegularParams, params);
      // console.log("--queryRegularParams--",this.queryRegularParams);
      // console.log("--params--",params);
      request({
        url:url,
        method:method,
        params:combinedObj,
      }).then(response =>{
        this.loading = false;
        if (response.code === 200){
          this.tableList = response.rows;
          console.log("---列表数据-----",this.tableList);
        }else {
          this.$message.error(response.message);
        }
        this.total = response.total;
        console.log('开始请求网络response=', response);
      }).catch(err=>{
        this.loading = false;
      })
    },
    searchAction(){
      console.log("查询");
      this.requestData(this.urlStr,this.method,this.queryParams);
    },
    resetAction(){
      console.log("重置");
      this.queryParams = {
        pageNum:1,
        pageSize:20,
      }
      this.requestData(this.urlStr,this.method,this.queryParams);
    },
    handleSizeChange(value){
      this.queryParams.pageSize = value;
      this.requestData(this.urlStr,this.method,this.queryParams);

    },
    handleCurrentChange(value){
      this.queryParams.pageNum = value;
      this.requestData(this.urlStr,this.method,this.queryParams);
    },
    handleSelectionChange(value){
      console.log("-------",value);
      this.multipleSelection = value;
    },
    refreshTableData(){
      this.requestData(this.urlStr,this.method,this.queryParams);
    }
  }
}
